package test_modele;

import static org.junit.Assert.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import modele.*;

import org.junit.Before;
import org.junit.Test;
/**
 * 
 * @author Plancq Charlotte, Lanvin Kévin, Darras Raphael
 *
 *
 */
public class TBdtheque {
	Bdtheque bdt;
	CollectionAlbums collection;
	ArrayList<CollectionAlbums>  listeTest;
	Album a,b,c;
	@Before
	public void setUp() throws IOException{
		bdt=new Bdtheque();
		listeTest=new ArrayList<CollectionAlbums>();
		collection=new CollectionAlbums(null, "Tous");
		a = new Album("Tintin au Tibet", "Hergé", "editeur", "aventure", "Tintin", "synopsis", 5, " "," ");
		b= new Album("Nitnit au Tebit","Géher",null,"l'Aaaaaventura","Nitnit","resumé", 6, "abcd"," ");
		c=new Album("Tintin au Tibet", "Hergé", "editeur", "aventure", "Tintin", "synopsis", 0, null,null);
		collection.add(a);
		collection.add(b);
		collection.add(c);
		listeTest.add(collection);
	}


	
	@Test
	public void testGetCollections() throws IOException{
		bdt.addAlbum(a, 0);
		bdt.addAlbum(b, 0);
		bdt.addAlbum(c, 0);
		assertEquals(listeTest, bdt.getCollections());
	}

	@Test
	public void testSetCollection(){
		ArrayList<CollectionAlbums> temp=new ArrayList<CollectionAlbums>();
		temp=listeTest;
		bdt.setCollections(temp);
		assertEquals(listeTest, bdt.getCollections());
	}
	
	@Test
	public void testGetAlbum(){
		bdt.addAlbum(a, 0);
		assertEquals(a, bdt.getAlbum(0) );
	}
	@Test
	public void testAddAlbum(){
		assertTrue(bdt.addAlbum(a, 0));
	}
	@Test
	public void testSupprimerAlbum(){
		assertFalse(bdt.supprimerAlbum(a, collection));
	}
	@Test
	public void testRechercherAlbum(){
		ArrayList<Album> listeT=new ArrayList<Album>();
		listeT.add(a);
		bdt.addAlbum(a, 0);
		assertEquals(listeT, bdt.rechercherAlbum(a));
	}
	@Test
	public void testGetAlbums(){
		ArrayList<Album> listeT=new ArrayList<Album>();
		listeT.add(a);
		listeT.add(b);
		listeT.add(c);
		bdt.addAlbum(a, 0);
		bdt.addAlbum(b, 0);
		bdt.addAlbum(c, 0);
		assertEquals(listeT, bdt.getAlbums());
	}
	@Test
	public void testGetAuteurs(){
		ArrayList<String> listeAuteurs=new ArrayList<String>();
		listeAuteurs.add("Hergé");
		listeAuteurs.add("Géher");
		bdt.addAlbum(a, 0);
		bdt.addAlbum(b, 0);
		assertEquals(listeAuteurs, bdt.getAuteurs());
	}
	@Test
	public void testGetEditeurs(){
		ArrayList<String> listeEditeurs=new ArrayList<String>();
		listeEditeurs.add("editeur");
		bdt.addAlbum(a, 0);
		assertEquals(listeEditeurs, bdt.getEditeurs());
	}
	@Test
	public void testGetGenres(){
		String [] temp = {"Action", "Anticipation", "Artbooks", "Aventure", "Documentaire", "Drame", "Erotique", "Esoterisme",
				"Fantastique", "Fantasy", "Guerre", "Heroic Fantasy", "Historique", "Horreur", "Humour", "Jeunesse", "Polar",
				"Romance", "Romans Graphiques", "Science Fiction", "Sport", "Thriller", "Tranches de vie", "Western"};
		ArrayList<String>listeGenres=new ArrayList<String>();
		for (int i =0; i<temp.length ; i++)
			listeGenres.add(temp[i]);
		assertEquals(listeGenres, bdt.getGenres());
	}
	@Test
	public void testGetTitres(){
		ArrayList<String> listeTitres=new ArrayList<String>();
		listeTitres.add("Tintin au Tibet");
		bdt.addAlbum(a, 0);
	
		assertEquals(listeTitres, bdt.getTitres());
	}
	@Test
	public void testGetAndSetAffichages(){
		bdt.setAffichage(42);
		assertEquals(42, bdt.getAffichage());
	}
	@Test
	public void testgetElementAt(){
		CollectionAlbums temp=new CollectionAlbums(bdt, " ");
		bdt.addCollection(temp);
		assertEquals(temp, bdt.getElementAt(1));
	}
	@Test
	public void testGetSize(){
		assertEquals(1,bdt.getSize());
	}
	@Test
	public void testAddCOllections(){
		CollectionAlbums temp=new CollectionAlbums(bdt, " ");
		bdt.addCollection(temp);
		assertEquals(2,bdt.getSize());

	}
}